<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of Configuration
 *
 * @author MinhNguyen
 */

class UserManagementController {
    //put your code here
    private $model;
    private $view;
    
    public function __construct($model, $view) {
        //allocate your stuff
        $this->model = $model;
        $this->view = $view;
    }
    
    /**
     * save users array to database
     * @return boolean
     */
    public function Save() {
        foreach ($this->model->users as $user) {
            $usercontroller = new UserController($user, null);
            $usercontroller->Save();
        }
        return true;
    }
    
    /**
     * delete users array in database
     * @return boolean
     */
    public function Delete() {
        foreach ($this->model->users as $user) {
            $usercontroller = new UserController($user, null);
            $usercontroller->Delete();
        }
        return true;
    }
    
    /**
     * get User in array by index
     * @param type $index
     * @return type
     */
    public function getUser($index) {
        return $this->model->users[$index];
    }
    
    /**
     * display users array
     */
    public function invoke() {
        $this->view->Display("UserManagementViewer.php", $this->model);
    }
}
?>
